<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文档转pdf</title>
    <script src="js/jquery.min.js"></script>
</head>
<body>
<h3>上传doc,docx,xls,xlsx,ppt,pptx，保存后即可转换成pdf</h3>
<input type="file" id="avatar" name="file">
<button type="button">保存</button>
<span id="tip"></span>
<div></div>
<script>
    $('button').click(function () {
        var files = $('#avatar').prop('files');
        $("#tip").html("上传中...")

        var data = new FormData();
        data.append('file', files[0]);
        $.ajax({
                url: '/upload',
                type: 'POST',
                data: data,
                cache: false,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 0) {

                        $("#tip").html("上传成功")

                    } else {
                        alert(data.msg);
                        $("#tip").html(data.msg)
                    }
                },
                error: function () {
                    alert("异常！");
                    $("#tip").html("异常")
                }
            }
        );
    });
</script>


</body>
</html>